package study.kit.uitls;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.io.resource.ResourceUtil;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;

@Slf4j
public class CompareUtils {

    String data1 = "data1.txt";

    String data2 = "data2.txt";

    @Test
    public void test() {
        InputStream is1 = ResourceUtil.getStream(data1);
        InputStream is2 = ResourceUtil.getStream(data2);

        List<String> data1Lt = new ArrayList<>();
        IoUtil.readLines(is1, Charset.defaultCharset(), data1Lt);
        List<String> data2Lt = new ArrayList<>();

        IoUtil.readLines(is2, Charset.defaultCharset(), data2Lt);
        CollectionUtil.forEach(data1Lt, (v, i) -> {
            if (!CollectionUtil.contains(data2Lt, v)) {
                log.info("{}", v);
            }
        });

        CollectionUtil.forEach(data2Lt, (v, i) -> {
            if (!CollectionUtil.contains(data1Lt, v)) {
                log.info("{}", v);
            }
        });
    }


    @Test
    public void test2() {
        InputStream is1 = ResourceUtil.getStream(data1);
        InputStream is2 = ResourceUtil.getStream(data2);

        List<String> data1Lt = new ArrayList<>();
        IoUtil.readLines(is1, Charset.defaultCharset(), data1Lt);
        List<String> data2Lt = new ArrayList<>();
        IoUtil.readLines(is2, Charset.defaultCharset(), data2Lt);

        log.info("{}, {}", data1Lt);
        log.info("{}, {}", data2Lt);
    }
}
